home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 21 / Mac Magazin and MacEasy Magazine CD - Issue 21.iso / Wissenschaft & Technik / yorick12vr1-nofpu folder / include / movie.i < prev    next >
Text File  |  1996-02-13  |  4KB  |  139 lines

  1. /*
  2.    MOVIE.I
  3.    Support functions for making animated sequences.
  4.  
  5.    $Id$
  6.  */
  7. /*    Copyright (c) 1995.  The Regents of the University of California.
  8.                     All rights reserved.  */
  9.  
  10. func movie(draw_frame, time_limit, min_interframe, bracket_time)
  11. /* DOCUMENT movie, draw_frame
  12.          or movie, draw_frame, time_limit
  13.          or movie, draw_frame, time_limit, min_interframe
  14.      runs a movie based on the given DRAW_FRAME function.  The movie
  15.      stops after a total elapsed time of TIME_LIMIT seconds, which
  16.      defaults to 60 (one minute), or when the DRAW_FRAME function
  17.      returns zero.
  18.  
  19.      func draw_frame(i)
  20.      {
  21.        // Input argument i is the frame number.
  22.        // draw_frame should return non-zero if there are more
  23.        // frames in this movie.  A zero return will stop the
  24.        // movie.
  25.        // draw_frame must NOT include any fma command if the
  26.        // making_movie variable is set (movie sets this variable
  27.        // before calling draw_frame)
  28.      }
  29.  
  30.      If MIN_INTERFRAME is specified, a pauses will be added as
  31.      necessary to slow down the movie.  MIN_INTERFRAME is a time
  32.      in seconds (default 0).
  33.  
  34.      The keyword bracket_time= (again a time in seconds) can be
  35.      used to adjust the duration of the pauses after the first
  36.      and last frames.  It may also be a two element array [beg, end].
  37.      If the pause at the end is greater than five seconds, you will
  38.      be prompted to explain that hitting <RETURN> will abort the final
  39.      pause.
  40.  
  41.      If every frame of your movie has the same limits, use the
  42.      limits command to fix the limits before you call movie.
  43.  
  44.    BUG:  If you hit <RETURN> to start a movie early, it will not
  45.          pause at the end of the movie at all.  You probably should
  46.      not use long initial pauses.
  47.  
  48.    SEE ALSO: movie_stats
  49.  */
  50. {
  51.   if (is_void(time_limit)) time_limit= 60.0;
  52.   if (is_void(min_interframe)) min_interframe= 0.0;
  53.   if (is_void(bracket_time)) bracket_time= [2.,2.];
  54.   else if (numberof(bracket_time)<2) bracket_time= array(bracket_time,2);
  55.  
  56.   elapsed= this_frame= array(0.0, 3);
  57.  
  58.   window, wait=1;  /* make sure window is ready to draw */
  59.   fma;             /* clear out any existing picture */
  60.   animate, 1;
  61.   making_movie= 1;
  62.  
  63.   i= 0;
  64.   timer, elapsed;
  65.   elapsed0= elapsed;
  66.   more= draw_frame(++i);
  67.   fma;
  68.   timer, elapsed, this_frame;
  69.   wait= bracket_time(1)-this_frame(3);
  70.   waited= waited0= 0.0;
  71.   if (wait>0) {
  72.     if (wait>5)
  73.       write,
  74.         format="Movie starts in %.0f secs, or when you hit <RETURN>\n", wait;
  75.     pause, long(1000.*wait);
  76.     waited0+= wait;
  77.   } else {
  78.     wait= min_interframe-this_frame(3);
  79.     if (wait>0) {
  80.       pause, long(1000.*wait);
  81.       waited+= wait;
  82.     }
  83.   }
  84.  
  85.   while (more) {
  86.     this_frame()= 0.0;
  87.     more= draw_frame(++i);
  88.     fma;
  89.     timer, elapsed, this_frame;
  90.     if (!more || (elapsed(3)-elapsed0(3))>time_limit) break;
  91.     wait= min_interframe-this_frame(3);
  92.     if (wait>0) {
  93.       pause, long(1000.*wait);
  94.       waited+= wait;
  95.     }
  96.   }
  97.  
  98.   wait= bracket_time(2)-this_frame(3);
  99.   if (wait>0) {
  100.     if (wait>5) {
  101.       write,
  102.         format="Holding last frame for %.0f secs, or hit <RETURN>\n", wait;
  103.       pause, 100;  /* huh? */
  104.     }
  105.     pause, long(1000.*wait);
  106.     waited0+= wait;
  107.   }
  108.   timer, elapsed;
  109.  
  110.   animate, 0;
  111.  
  112.   extern movie_timing;
  113.   movie_timing= grow(elapsed-elapsed0, i, waited, waited0);
  114. }
  115.  
  116. func movie_stats(timing)
  117. /* DOCUMENT movie_stats
  118.          or movie_stats, timing
  119.      prints statistics from the last movie command, or from the
  120.      command which produced TIMING.  TIMING is the contents of the
  121.      movie_timing external variable after the movie command completes.
  122.  
  123.    SEE ALSO: movie
  124.  */
  125. {
  126.   if (is_void(timing)) timing= movie_timing;
  127.   cpu= timing(1)+timing(2);
  128.   wall= timing(3);
  129.   nframes= long(timing(4));
  130.   waited= timing(5)+timing(6);
  131.   wait= timing(5);
  132.  
  133.   write, format="  Wall(sec)  Wait(sec)  CPU(sec)%s\n", "";
  134.   write, format="  %9.3f  %9.3f  %8.3f   %ld frames\n",
  135.          wall, waited, cpu, nframes;
  136.   write, format="  %9.3f  %9.3f  %8.3f   per frame\n",
  137.          (wall-waited)/nframes, wait/(nframes>1?nframes-1:1), cpu/nframes;
  138. }
  139.